<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\8\20 0020
 * Time: 18:47
 */

namespace Home\Controller;


use Think\Controller;

class MobilepayController extends Controller
{

    public function _initialize(){
        vendor("Qrcode.qrcode");
    }
    /**
     * @func 建设银行手机支付
     * @param money 支付金额
     * @author LX
     * @date 2018-8-21
     * @return JSON
     */
    public function CCBmobilepay($money,$orderid){
        //需要支付的金额
//        var_dump($money,$orderid);die;
        $ord['orderid'] = $orderid;
        $isorder = M('xllog')->where($ord)->field('openid')->find();
//        if (empty($isorder['openid'])){
//            return '订单未指定司机';
//        }
        $param=C('CCB');
        $param['ORDERID']=$orderid;
        $param['PAYMENT']=$money;
        $param['CURCODE']='01';                //币种
        $param['TXCODE']='530550';              //交易码
        $param['REMARK1']='';
        $param['REMARK2']='';
        $param['RETURNTYPE']=3;
        $param['TIMEOUT']='';
        $param['PUB']=substr(C('CCBKEY.PUBLICKEY'),(strlen(C('CCBKEY.PUBLICKEY'))-30));
        $param_str = http_build_query($param);          //加密字串
        $param['MAC']=md5($param_str);
        $param_str = http_build_query($param);          //发送参数
        $url = "https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain?CCB_IBSVersion=V6";
        $result = doPost($url,$param_str);
        if($result){
            $ccb_result=json_decode($result,true);
            if($ccb_result['SUCCESS']){
                $param_result=doPost($ccb_result['PAYURL']);
                $canshu=json_decode($param_result,true);
                if($canshu['SUCCESS']) {
                    $pay_urltext = urldecode($canshu['QRURL']);
                    $level = 0;
                    $size = 10;
                    $padding = 1;
                    $result_weixin = \QRcode::png($pay_urltext, FALSE, $level, $size, $padding, false, true);
//                    $this->assign('data',$result_weixin['result']);
//                    return $this->fetch();
                    return $result_weixin;
                }else{
                    datamsg(0,'返回链接错误','');
                }
            }else{
                datamsg(0,'请求出错','');
            }
        }else{
            datamsg(0,'请求失败','');
        }
    }

    public function Payresult(){
      $result = PayApiController::returnapi();
      file_put_contents('1.txt',json_encode($result));
    }
//if (empty($money)){
//datamsg(0,'支付金额不能为空');
//}
////生成唯一的字符串
//$unqiue = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 6);
////获取商户配置信息
//$param = C('CCB');
////唯一的订单号
//$param['ORDERID'] = $unqiue;
////账单金额
//$param['PAYMENT'] = $money;
////付款币种
//$param['CURCODE'] = '01';
////交易码
//$param['TXCODE'] = '520100';
////备注1
//$param['REMARK1'] = '';
////备注2
//$param['REMARK2'] = '';
////接口类型（防钓鱼）
//$param['TYPE'] = '1';
////公钥后三十位数据
//$param['PUB'] = substr(C('CCBKEY.PUBLICKEY'),(strlen(C('CCBKEY.PUBLICKEY'))-30));
////网关类型
//$param['GATEWAY'] = '';
//$param['CLIENTIP'] = '192.168.0.162';
//$param['REGINFO'] = 'xiaofeixia';
//$param['PROINFO'] = 'digital';
////
//$param['REFERER'] = '';
//
////加密前字符串
//$param_str = http_build_query($param);
////md5mac字符串
//$param['MAC'] = md5($param_str);
//unset($param['PUB']);
////银行参数数据
//$param_str = http_build_query($param);
////接口url
//$url = 'https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain?';
////获取结果
////        var_dump($param_str);die;
//$result = doPost($url,$param_str);
//
//
//return $result;

}